package com.atguigu.rabbitmq.Three;

import com.atguigu.rabbitmq.utils.RabbitMqUtils;
import com.atguigu.rabbitmq.utils.SleepUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import com.rabbitmq.client.Delivery;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Work03 {
    private static final String QUEUE_NAME="ack_queue";

    public static void main(String[] args) throws IOException, TimeoutException {
        Channel channel = RabbitMqUtils.getChannel();
        System.out.println("C1等待接收消息处理时间较短");
        channel.basicQos(2);
        channel.basicConsume(QUEUE_NAME, false, (consumerTag, message)->{
            SleepUtils.sleep(1);
            System.out.println("接收到的消息"+new String(message.getBody()));
            channel.basicAck(message.getEnvelope().getDeliveryTag(),false) ;
        },consumerTag->{
            System.out.println(consumerTag+"消息着取消消费接口回调逻辑");
        });
    }
}
